$(document).ready(
		function() {
			$("form").submit(function() {
				return false;
			});
			var VAL = {
				NORMAL : "0000000",
				EVT_USER : $("#userId").text(),
				/*EVT_USER : "C1702003",*/
				T_FSPBOXOPE: "FSPBOXOPE",
				T_FIPINQBOX: "FIPINQBOX",
				DISABLED_ATTR : {
					"disabled" : true
				},
				ENABLED_ATTR : {
					"disabled" : false
				}
			};
			var domObj = {
				$window : $(window),

				$boxIdFk : $("#boxIdFk"),
				$boxId : $("#boxId"),
				$boxStat : $("#boxStat"),
				$realEmp : $("#realEmp"),
				$prdQty : $("#prdQty"),
				$prdQtys : $("#prdQtys"),
				$mdlIdFk : $("#mdlIdFk"),
				$groupId : $("#groupId"),
				$acRecipeId : $("#acRecipeId"),
				$boxOwn : $("#boxOwn"),
				$prdGradeFk : $("#prdGradeFk"),
				$woIdFk    : $("#woIdFk"),
				$prty : $("#prty"),
				$destShop : $("#destShop"),
				$boxUseCnt : $("#boxUseCnt"),
				$maxUseCnt: $("#maxUseCnt"),
                $boxSetCode : $("#boxSetCode"),
				$boxCleanFlg : $("#boxCleanFlg"),
				/*最后清洁日期/时间
				$lastCleanTime :$("#lastCleanTime"),*/
				/*卡匣备注信息*/
				$boxNote : $("#boxNote"),
				/*---制程----*/
				$nxPathIdFk : $("#nxPathIdFk"),
				$nxPathVerFk : $("#nxPathVerFk"),
				$nxOpeNo : $("#nxOpeNo"),
				$nxOpeId : $("#nxOpeId"),
				$nxOpeVer : $("#nxOpeVer"),
				$nxProcIdFk : $("#nxProcIdFk"),
				$toolIdFK : $("#toolIdFK"),
				$toolPortIdFK : $("#toolPortIdFK"),
				//输入的note
				$note : $("#note"),
				
				buttons : {
					$query_btn : $("#query_btn"),
					$clean_btn : $("#clean_btn"),
					$cleanCancel_btn : $("#cleanCancel_btn"),
					$empty_btn : $("#empty_btn"),
					$note_btn : $("#note_btn")
				},

			};

			var buttonFnc = {
				queryFnc : function() {
					var boxIdFk,iary, inObj, outObj;
					boxIdFk = domObj.$boxIdFk.val().trim();
					if(!boxIdFk){
						showErrorDialog("", "卡匣代码不能为空！");
						return false;
					}
					inObj = {
							trx_id : VAL.T_FIPINQBOX,
							action_flg : 'Q',
							box_id :boxIdFk,
						};
					outObj = comTrxSubSendPostJson(inObj);
					if (outObj.rtn_code === VAL.NORMAL) {
						domObj.$boxId.val(outObj.box_id);
						domObj.$boxStat.val(outObj.box_stat);
						domObj.$realEmp.val(outObj.real_emp);
						domObj.$prdQty.val(outObj.prd_qty);
						domObj.$prdQtys.val(outObj.chip_qty);
						domObj.$mdlIdFk.val(outObj.mdl_id_fk);
                        domObj.$woIdFk.val(outObj.wo_id_fk);
						domObj.$groupId.val(outObj.group_id);
						domObj.$acRecipeId.val(outObj.ac_recipe_id);
						domObj.$boxOwn.val(outObj.box_own);
						domObj.$prdGradeFk.val(outObj.prd_grade_fk);
						domObj.$prty.val(outObj.prty);
						domObj.$destShop.val(outObj.dest_shop);
						domObj.$boxUseCnt.val(outObj.box_use_cnt);
						domObj.$maxUseCnt.val(outObj.max_use_cnt);
						domObj.$boxSetCode.val(outObj.box_set_code);
						domObj.$boxCleanFlg.val(outObj.box_clean_flg);
						/*domObj.$lastCleanTime.val(outObj.comp_date);*/
						//备注信息
						domObj.$boxNote.val(outObj.box_note);
						domObj.$nxPathIdFk.val(outObj.nx_path_id_fk);
						domObj.$nxPathVerFk.val(outObj.nx_path_ver_fk);
						domObj.$nxOpeNo.val(outObj.nx_ope_no_fk);
						domObj.$nxOpeId.val(outObj.nx_ope_id_fk);
						domObj.$nxOpeVer.val(outObj.nx_ope_ver_fk);
						domObj.$nxProcIdFk.val(outObj.nx_proc_id_fk);
						domObj.$toolIdFK.val(outObj.tool_id_fk);
						domObj.$toolPortIdFK.val(outObj.tool_port_id_fk);
						if(outObj.box_clean_flg == "Y"){
                            domObj.$boxCleanFlg.css("color","red");
						}else{
                            domObj.$boxCleanFlg.css("color","black");
						}
					}

				},

				cleanFnc : function() {
					var boxId, id, inObj,outObj,iary;
					boxId = domObj.$boxIdFk.val().trim();
					if(!boxId){
						showErrorDialog("", "卡匣代码不能为空，请先输入再执行清洗请求！");
						return false;
					}
                    var box_id = domObj.$boxId.val();
                    if(!box_id){
                        showErrorDialog("", "请先获取卡匣信息，再执行清洗请求！");
                        return false;
                    }
					iary ={
							box_id : boxId,
					};
					
					inObj = {
						trx_id : VAL.T_FSPBOXOPE,
						action_flg : 'C',
						iary : [iary],
					};
					outObj = comTrxSubSendPostJson(inObj);
					if (outObj.rtn_code === VAL.NORMAL) {
                        buttonFnc.queryFnc();
						showSuccessDialog("清洗请求成功!");
					}
				},

				// cancelCleanFn : function (){
				// 	var boxId, id, inObj,outObj,iary;
				// 	boxId = domObj.$boxIdFk.val();
				// 	if(!boxId){
				// 		showErrorDialog("", "卡匣代码不能为空，请先输入再执行取消清洗请求！");
				// 		return false;
				// 	}
				// 	iary ={
				// 			box_id : boxId,
				// 	};
				//
				// 	inObj = {
				// 		trx_id : VAL.T_FSPBOXOPE,
				// 		action_flg : 'N',
				// 		iary : [iary],
				// 	};
				// 	outObj = comTrxSubSendPostJson(inObj);
				// 	if (outObj.rtn_code === VAL.NORMAL) {
				// 		var oary = outObj.oary[0];
				// 		domObj.$boxCleanFlg.val(oary.box_clean_flg);
				// 		showSuccessDialog("取消清洗请求成功!");
				// 	}
				// },
				
				emptyFnc : function (){
					var boxId, id, inObj,outObj,iary;
					boxId = domObj.$boxIdFk.val();
					if(!boxId){
						showErrorDialog("", "卡匣代码不能为空，请先输入再执行空请求！");
						return false;
					}
					var box_id = domObj.$boxId.val();
                    if(!box_id){
                        showErrorDialog("", "请先获取卡匣信息，再执行空请求！");
                        return false;
                    }
					iary ={
							box_id : box_id,
					};
					
					inObj = {
						trx_id : VAL.T_FSPBOXOPE,
						action_flg : 'E',
						iary : [iary],
					};
					outObj = comTrxSubSendPostJson(inObj);
					if (outObj.rtn_code === VAL.NORMAL) {
                        buttonFnc.queryFnc();
						showSuccessDialog("空请求成功!");
					}
				} ,
				
				noteFnc : function (){
					var boxId = domObj.$boxIdFk.val();
					if(!boxId){
						showErrorDialog("", "卡匣代码不能为空，请先输入再执行卡匣备注请求！");
						return false;
					}
                    var box_id = domObj.$boxId.val();
                    if(!box_id){
                        showErrorDialog("", "请先获取卡匣信息，再进行卡匣备注！");
                        return false;
                    }
					$('#addNoteDialog').modal({
						backdrop : true,
						keyboard : false,
						show : false
					});
					
					$('#addNoteDialog').unbind('shown.bs.modal');
					$("#noteDialog_sureBtn").unbind('click');
					$('#addNoteDialog').bind('shown.bs.modal');
					$('#addNoteDialog').modal("show");
					//模态框查询按钮绑定查询函数
					$("#noteDialog_sureBtn").bind('click', queryDialog.noteRegister);
					$("#addNoteDialog textarea").attr(VAL.ENABLED_ATTR);
					$('#addNoteDialog textarea').val("");
				}

			};

			var queryDialog = {
                noteRegister : function (){
						var boxNote,boxId,iary,inObj,outObj
						boxNote = domObj.$note.val();
                        boxId = domObj.$boxId.val();
						if(!boxNote){
							showErrorDialog("", "备注信息不能为空！");
							return false;
						}
						iary ={
								box_note : boxNote,
								box_id : boxId
						};
						
						inObj = {
							trx_id : VAL.T_FSPBOXOPE,
							action_flg : 'T',
							iary : [iary],
						};
						outObj = comTrxSubSendPostJson(inObj);
						if (outObj.rtn_code === VAL.NORMAL) {
							var oary = outObj.oary[0];
							domObj.$boxNote.val(oary.box_note);
							showSuccessDialog("备注成功!");
							$('#addNoteDialog').modal("hide");
						}
					}
			}
			
			
			domObj.$boxIdFk.keydown(function(event) {
				if (event.keyCode == 13) {
                    buttonFnc.queryFnc();
				}
			});

			
			function initPage(){
				domObj.$boxIdFk.val("");
                $(".inputValue").val("");
                domObj.$boxIdFk.focus();
				domObj.buttons.$query_btn.bind('click', buttonFnc.queryFnc);
				domObj.buttons.$clean_btn.bind('click', buttonFnc.cleanFnc);
				domObj.buttons.$cleanCancel_btn.bind('click', buttonFnc.cancelCleanFn);
				domObj.buttons.$empty_btn.bind('click', buttonFnc.emptyFnc);
				domObj.buttons.$note_btn.bind('click', buttonFnc.noteFnc);
			};
			
			initPage();
		})